package javaStudy.io流;

import java.io.*;
//字符缓冲流
public class BufferedStreamDemo {
    public static void main(String[] args) throws IOException {
        BufferedWriter bw=new BufferedWriter(new FileWriter("bw.txt"));
        for (int i=0;i<5;i++){
            bw.write("hello");
            bw.newLine();
            bw.write("世界");
            //换行
            bw.newLine();
            //刷新
            bw.flush();
        }
        bw.close();

        BufferedReader br=new BufferedReader(new FileReader("bw.txt"));
        //一次读一个数据
        /*
        int by;
        while ((by=br.read())!=-1){
            System.out.print((char)by);
        }
         */
//        一次读一个字符数组
        /*
        char[] bytes=new char[1024];
        int len;
        while((len= br.read(bytes))!=-1){
            System.out.println(new String(bytes,0,len));
        }
         */
        //readline一次读一行，但是只读内容不读换行符
        String line;
      while((line= br.readLine())!=null){
          System.out.println(line);
      }
        br.close();
    }
}
